package com.ruoyi.qyj.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qyj.mapper.TbRecordPatrolMapper;
import com.ruoyi.qyj.domain.TbRecordPatrol;
import com.ruoyi.qyj.service.ITbRecordPatrolService;

/**
 * 巡查记录信息Service业务层处理
 * 
 * @author yellow
 * @date 2023-05-24
 */
@Service
public class TbRecordPatrolServiceImpl implements ITbRecordPatrolService 
{
    @Autowired
    private TbRecordPatrolMapper tbRecordPatrolMapper;

    /**
     * 查询巡查记录信息
     * 
     * @param recordId 巡查记录信息主键
     * @return 巡查记录信息
     */
    @Override
    public TbRecordPatrol selectTbRecordPatrolByRecordId(Long recordId)
    {
        return tbRecordPatrolMapper.selectTbRecordPatrolByRecordId(recordId);
    }

    /**
     * 查询巡查记录信息列表
     * 
     * @param tbRecordPatrol 巡查记录信息
     * @return 巡查记录信息
     */
    @Override
    public List<TbRecordPatrol> selectTbRecordPatrolList(TbRecordPatrol tbRecordPatrol)
    {
        return tbRecordPatrolMapper.selectTbRecordPatrolList(tbRecordPatrol);
    }

    /**
     * 新增巡查记录信息
     * 
     * @param tbRecordPatrol 巡查记录信息
     * @return 结果
     */
    @Override
    public int insertTbRecordPatrol(TbRecordPatrol tbRecordPatrol)
    {
        tbRecordPatrol.setCreateTime(DateUtils.getNowDate());
        return tbRecordPatrolMapper.insertTbRecordPatrol(tbRecordPatrol);
    }

    /**
     * 修改巡查记录信息
     * 
     * @param tbRecordPatrol 巡查记录信息
     * @return 结果
     */
    @Override
    public int updateTbRecordPatrol(TbRecordPatrol tbRecordPatrol)
    {
        tbRecordPatrol.setUpdateTime(DateUtils.getNowDate());
        return tbRecordPatrolMapper.updateTbRecordPatrol(tbRecordPatrol);
    }

    /**
     * 批量删除巡查记录信息
     * 
     * @param recordIds 需要删除的巡查记录信息主键
     * @return 结果
     */
    @Override
    public int deleteTbRecordPatrolByRecordIds(Long[] recordIds)
    {
        return tbRecordPatrolMapper.deleteTbRecordPatrolByRecordIds(recordIds);
    }

    /**
     * 删除巡查记录信息信息
     * 
     * @param recordId 巡查记录信息主键
     * @return 结果
     */
    @Override
    public int deleteTbRecordPatrolByRecordId(Long recordId)
    {
        return tbRecordPatrolMapper.deleteTbRecordPatrolByRecordId(recordId);
    }

    /**
     *
     * 导入巡查记录数据
     * @param file 文件
     * @return
     */
    @Override
    public int importExcel(MultipartFile file) {
        ExcelUtil excelUtil = new ExcelUtil(TbRecordPatrol.class);
        List<TbRecordPatrol> tbRecordPatrolList = new ArrayList<>();
        try {
            tbRecordPatrolList = excelUtil.importExcel(file.getInputStream(), 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        for (TbRecordPatrol tbRecordPatrol:tbRecordPatrolList) {
            tbRecordPatrolMapper.insertTbRecordPatrol(tbRecordPatrol);
        }
        return tbRecordPatrolList.size();
    }

    @Override
    public TbRecordPatrol selectTbRecordPatrolTotal() {
        return tbRecordPatrolMapper.selectTbRecordPatrolTotal();
    }
}
